
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

module.exports = [
  // user login
  {
    url: '/vue-admin-template/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/vue-admin-template/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        statusCode: 200,
        data: 'success'
      }
    }
  },

  // user menu
  {
    url: '/vue-admin-template/user/getAuthMenu',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: [
          {
            id: 5,
            path: '/example',
            component: '#',
            redirect: '/example/table',
            name: 'Example',
            label: '列表管理',
            meta: { title: 'Example', icon: 'el-icon-s-help' },
            children: [
              {
                id: 6,
                path: 'table',
                name: 'Table',
                label: '表格',
                component: '/table/index',
                meta: { title: 'Table', icon: 'table', roles: ['editor'] }
              },
              {
                id: 7,
                path: 'tree',
                name: 'Tree',
                label: '树状表格',
                component: '/tree/index',
                meta: { title: 'Tree', icon: 'tree' }
              }
            ]
          },
          {
            id: 8,
            path: '/form',
            component: '#',
            label: '表单管理',
            meta: { title: 'Form', icon: 'form' },
            children: [
              {
                id: 9,
                path: 'index',
                name: 'Form',
                label: '表单',
                component: '/form/index',
                meta: { title: 'Form', icon: 'form' }
              }
            ]
          },
          {
            id: 18,
            path: '/role',
            component: '#',
            label: '权限管理',
            meta: { title: 'role', icon: 'el-icon-s-custom' },
            redirect: '/role/roleindex',
            name: 'Role',
            children: [
              {
                id: 19,
                path: 'roleindex',
                name: 'Rolendex',
                label: '页面权限',
                component: '/role/index',
                meta: { title: 'pagerole', icon: 'el-icon-s-management', roles: ['editor'] }
              },
              {
                id: 20,
                path: 'actionindex',
                name: 'Actionindex',
                label: '功能权限',
                component: '/role/action',
                meta: { title: 'actionrole', icon: 'el-icon-s-tools', roles: ['editor'] }
              },
              {
                id: 22,
                path: 'directory',
                name: 'Airectory',
                label: '目录设置',
                component: '/role/directory',
                meta: { title: 'directory', icon: 'el-icon-s-order'}
              }
            ]
          },
          {
            id: 23,
            path: '/coupon',
            component: '#',
            label: '优惠券管理',
            meta: { title: 'coupon', icon: 'el-icon-s-management' },
            redirect: '/coupon/couponlist',
            name: 'Coupon',
            children: [
              {
                id: 24,
                path: 'couponlist',
                name: 'Rouponlist',
                label: '页面权限',
                component: '/coupon/index',
                meta: { title: 'couponlist', icon: 'el-icon-s-ticket', roles: ['editor'] }
              }
            ]
          }
        ]
      }
    }
  }
]
